/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFVMEEvent
  \brief class for holding an event for VME daq
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-09-27
  \date 2021-09-28 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date        <th>Author      <th>Description                    </tr>
  <tr>  <td>2021-09-27   <td>Asia Sun    <td>file created                   </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFVMEEvent_h
#define ETFVMEEvent_h

#include <array>
#include <TNamed.h>
#include "vme_event_head.h"

using std::array;

struct section_head;
class TClonesArray;
class FairEventHeader;

class ETFVMEEvent : public TNamed{
public:
  ETFVMEEvent();
  ETFVMEEvent(const ETFVMEEvent &sec);
  virtual ~ETFVMEEvent();

  virtual void Reset(); ///< clear fEvent for next event
  ///@{ getters
  const vme_event_head &GetEventHead() const{ return fEventHead; }
  vme_event_head &GetEventHead(){ return fEventHead; }
  const array<unsigned, 16> &GetSca() const{ return fSca; }
  const array<unsigned, 16> &GetPSca() const{ return fPSca; }
  const array<int, 16> &GetDSca() const{ return fDSca; }
  array<unsigned, 16> &GetSca(){ return fSca; }
  array<unsigned, 16> &GetPSca(){ return fPSca; }
  array<int, 16> &GetDSca(){ return fDSca; }
  unsigned GetBunchID() const{ return fBunchID; }
  unsigned GetEventID() const{ return fEventID; }
  TClonesArray *GetHPTDCChannels() const;
  TClonesArray *GetAmplitudeChannels() const;
  ///@}

  ///@{ setters
  void SetBunchID(unsigned bunchID){ fBunchID = bunchID; }
  void SetEventID(unsigned eventID){ fEventID = eventID; }
  ///@}

  virtual void PrintBunchID() const;
  virtual void PrintEventID() const;
  virtual void Print() const;

  friend class ETFVMEUnpacker;

  ClassDef(ETFVMEEvent, 1); ///< VME data section class

protected:
  vme_event_head fEventHead; ///< containin event index and event length
  /// \NOTE that since VME already has its data's time stamp subtracted by trig,
  /// the bunchID has lost its value, i.e., we don't use fBunchID here to get
  /// relative time, since it is already relative
  unsigned fBunchID; ///< bunchID: trigger time tag
  unsigned fEventID; ///< eventID: from event counter
  /// scaler plugin for counting purposes
  array<unsigned, 16> fSca, fPSca; ///< [p]revious scaler
  array<int, 16> fDSca; ///< d[elta]-scaler
  TClonesArray *fHPTDCChannels; //! for HPTDC time channels
  TClonesArray *fAmplitudeChannels; //! for amplitudes, e.g. MUSIC & TAC signals
};

#endif
